<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="comments" class="clearfix" th:fragment="comments(comments,article,type)">

<div class="comments-box">
    <!--<h3 class="comments-title">全部评论：<span class="comments-num">1977条</span></h3>-->
    <div id="loading-comments"><span><i class="icon-spin6 animate-spin"></i> 加载中...</span></div>
    <ol class="commentlist">
        <li class="comment even thread-even depth-1" id="li-comment-67124"
            th:each="comment:${comments.list}">
            <div th:id="'comment-'+${comment.commentId}">
                <div class="comment-avatar">
                    <img th:src="${comment.userImg}" class='avatar avatar-96 photo' height='96'
                         width='96'/>
                </div>
                <div class="comment-body">
                    <div class="comment_author">
                        <span class="name" th:text="${comment.userName}">DostineX</span>
                        <em th:text="${comment.createTime}">2019-02-28 11:20</em>
                    </div>
                    <div class="comment-text">
                        <p th:text="${comment.content}"></p>
                    </div>
                    <div class="comment_reply">
                                            <span>
                                                <a th:if="${session.user!=null}" rel='nofollow' class='comment-reply-link' onclick='hui(0)'>
                                                    回复</a>
                                                <a th:if="${session.user==null}" rel='nofollow' class='comment-reply-link' onclick='hui(1)'>
                                                    回复</a>
                                            </span>
                    </div>
                </div>
            </div>
            <ul class="children">
                <li class="comment byuser comment-author-cookieking bypostauthor odd alt depth-2"
                    id="li-comment-67136" th:each="reply:${comment.commentReply}">
                    <div id="comment-67136">

                        <div class="comment-avatar">
                            <img th:src="${reply.userImg}" class='avatar avatar-96 photo'
                                 height='96' width='96'/>
                        </div>
                        <div class="comment-body">
                            <div class="comment_author">
                                <span class="name" th:text="${reply.userName}">thisding 资源共享网</span>
                                <!--<span class='comment_admin'>官方</span>-->
                                <em th:text="${reply.createTime}">2019-02-28 15:25</em>
                            </div>
                            <div class="comment-text">
                                <p th:text="${reply.content}">谢谢支持，请注意查收你的邮箱</p>
                            </div>
                            <div class="comment_reply">
                                                    <span>
                                                        <a rel='nofollow' class='comment-reply-link' href="#respond"
                                                           onclick='return addComment.moveForm( "comment-67136", "67136", "respond", "9531" )'>回复</a>
                                                    </span>
                            </div>
                        </div>
                    </div>
                </li>
            </ul><!-- .children -->
        </li>

    </ol><!-- .comment-list -->
    <!--<div id="comments-navi">
        <a class="prev page-numbers" href=""><i class="icon-left-open-1"></i></a>
        <a class='page-numbers' href=''>1</a>
        <span class="page-numbers dots">&hellip;</span>
        <a class='page-numbers' href='https://www.waitsun.com/xpay-html/comment-page-104#comments'>104</a>
        <a class='page-numbers' href='https://www.waitsun.com/xpay-html/comment-page-105#comments'>105</a>
        <span aria-current='page' class='page-numbers current'>106</span>
    </div>-->

</div>


<div id="respond" class="respond-box">
    <!--<h3 class="comments-title">发表评论 <span id="cancel-comment-reply"><a rel="nofollow" id="cancel-comment-reply-link" href="/swift-publisher.html#respond" style="display:none;">点击这里取消回复。</a></span></h3>-->
    <form method="post" id="commentform">
        <input type="hidden" name="articleId" id="articleId" th:value="${article.id}"/>
        <input type="hidden" name="objType" th:value="${type}"/>
        <!--<div id="comment-author-info" class="clearfix">
            <div class="comment-md-3">
                <label for="author">昵称<span class="required">*</span></label>
                <input type="text" th:if="${session.user==null}" name="userName" id="author" class="comment-md-9" value=""
                       size="22"
                       tabindex="1"/>
                <input type="text" th:if="${session.user!=null}" name="userName" id="author" class="comment-md-9" th:value="${session.user.userName}"
                       size="22"
                       tabindex="1"/>
            </div>
            <div class="comment-md-3">
                <label for="email">邮箱<span class="required">*</span></label>
                <input type="email" th:if="${session.user!=null}" name="email" id="email" class="comment-md-9" th:value="${session.user.email}" size="22"
                       tabindex="2"/>
                <input type="email" th:if="${session.user==null}" name="email" id="email" class="comment-md-9"  size="22"
                       tabindex="2"/>
            </div>
            <div class="comment-md-3 comment-form-url">
                <label for="url">网址<span class="required"></span></label>
                <input type="text" name="url" id="url" class="comment-md-9" value="" size="22"
                       tabindex="3"/>
            </div>
        </div>-->
        <input type="email" th:if="${session.user!=null}" name="email" id="email" class="comment-md-9" th:value="${session.user.email}" size="22" style="display: none"/>
        <div class="comment-from-main clearfix">
            <div class="comment-form-textarea">
                <div class="comment-textarea-box">
                    <textarea class="comment-textarea" name="content" id="comment_content" placeholder="说点什么吧..."></textarea>
                </div>
            </div>

            <div class="form-submit">

                <input class="btn-comment pull-right" onclick="addArtComment()"
                       style="text-align: center;" id="submit" tabindex="5" title="发表评论"
                       value="发表评论">
                <p style="display: none;">
                    <!--<p style="display: none;"><input type="hidden" id="ak_js" name="ak_js" value="123"/>-->
                </p>
            </div>

        </div>

    </form>
    <script type="text/javascript" >    //Crel+Enter
    function hui(ni){

        layui.use('layer', function(){
            var layer = layui.layer;
            if(ni==1){
                layer.msg('请先登录');
                return;
            }else {
                var type=[[${type}]];
                var artId=[[${article.id}]];
                var email=$("#email").val();
                var username=$("#author").val();
                layer.open({
                    type: 1,
                    content: '<div id="respondcopy" class="respond-box" ' +
                        '    <h3 class="comments-title">发表评论 <span id="cancel-comment-reply"><a rel="nofollow" id="cancel-comment-reply-link" href="/swift-publisher.html#respond" style="display:none;">点击这里取消回复。</a></span></h3>' +
                        '    <form method="post" id="commentform">' +
                        '        <input type="hidden" name="articleId" id="articleId" th:value="'+artId+'"/>' +
                        '        <input type="hidden" name="objType" value="'+type+'"/>' +
                        '        <div id="comment-author-info" class="clearfix">' +
                        '            <div class="comment-md-3">' +
                        '                <label for="author">昵称<span class="required">*</span></label>' +
                        '                <input type="text" name="userName" id="author" class="comment-md-9" value="'+username+'"' +
                        '                       size="22"' +
                        '                       tabindex="1"/>' +
                        '            </div>' +
                        '            <div class="comment-md-3">' +
                        '                <label for="email">邮箱<span class="required">*</span></label>' +
                        '                <input type="email" name="email" id="email" class="comment-md-9" value="'+email+'" size="22"' +
                        '                       tabindex="2"/>' +
                        '            </div>' +
                        '            <div class="comment-md-3 comment-form-url">' +
                        '                <label for="url">网址<span class="required"></span></label>' +
                        '                <input type="text" name="url" id="url" class="comment-md-9" value="" size="22"' +
                        '                       tabindex="3"/>' +
                        '            </div>' +
                        '        </div>' +
                        '        <div class="comment-from-main clearfix">' +
                        '            <div class="comment-form-textarea">' +
                        '                <div class="comment-textarea-box">' +
                        '                    <textarea class="comment-textarea" name="content" id="comment_contents" placeholder="说点什么吧..."></textarea>' +
                        '                </div>' +
                        '            </div>' +
                        '' +
                        '            <div class="form-submit">' +
                        '' +
                        '                <input class="btn-comment pull-right" onclick="addArtComments()"' +
                        '                       style="text-align: center;" id="submit" tabindex="5" title="发表评论"' +
                        '                       value="发表评论">' +
                        '                <p style="display: none;">' +
                        '                    <!--<p style="display: none;"><input type="hidden" id="ak_js" name="ak_js" value="123"/>-->' +
                        '                </p>' +
                        '            </div>' +
                        '' +
                        '        </div>' +
                        '' +
                        '    </form>' +
                        '</div>'
                });
            }

        });
    }
    //<![CDATA[
    jQuery(document).keypress(function (e) {
        if (e.ctrlKey && e.which == 13 || e.which == 10) {
            jQuery("#submit").click();
            document.body.focus();
        } else if (e.shiftKey && e.which == 13 || e.which == 10) {
            jQuery("#submit").click();
        }
    })

    // ]]>
    function addArtComment() {
        var user=[[${session.user==null}]]
        if(user){
            layui.use('layer', function(){
                var layer = layui.layer;

                layer.msg('请先登录');
            });
            return;
        }else{
            var d = {};
            var vals = $("#commentform").serializeArray();
            $.each(vals, function () {
                d[this.name] = this.value;
            });
            d.content = $('#comment_content').val();
            var data = JSON.stringify(d);
            $.ajax({
                url: '/articalComment/addComment',
                type: 'post',
                data: data,
                contentType: 'application/json',
                success: function (res) {
                    console.log(d)
                    if(d.objType=='0') {
                        location.href = "/download/article/findArticleById?id=" + d.articleId;
                    }else if(d.objType=='1'){
                        location.href ='/aboutus';
                    }else if(d.objType=='2'){
                        location.href="/sponsor";
                    }
                }
            });
            return false;
        }

    }

    function addArtComments() {
        var user=[[${session.user==null}]]
        if(user){
            layui.use('layer', function(){
                var layer = layui.layer;

                layer.msg('请先登录');
            });
            return;
        }else{
            var d = {};
            var vals = $("#commentform").serializeArray();
            $.each(vals, function () {
                d[this.name] = this.value;
            });
            d.content = $('#comment_contents').val();
            var data = JSON.stringify(d);
            $.ajax({
                url: '/articalComment/addComment',
                type: 'post',
                data: data,
                contentType: 'application/json',
                success: function (res) {
                    console.log(d)
                    if(d.objType=='0') {
                        location.href = "/download/article/findArticleById?id=" + d.articleId;
                    }else if(d.objType=='1'){
                        location.href ='/aboutus';
                    }else if(d.objType=='2'){
                        location.href="/sponsor";
                    }
                }
            });
            return false;
        }

    }
    </script>
</div>
</div>



</body>
</html>